-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] feat: support constant folding in translate_index_expr
[1/1]
#19972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[mypyc] feat: support constant folding in translate_index_expr
[1/1]
#19972
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
mypyc/irbuild/expression.py
Outdated
if ( | ||
isinstance(base.type, RTuple) | ||
and isinstance(folded_index := constant_fold_expr(builder, index), int) | ||
and folded_index >= 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for index overflow (it may generate an error elsewhere, but we don't want to crash the compiler if it's ignored).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I also just thought about reverse indexing, I'll implement that too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to adapt TupleGet before we can pass negative values here.
I've implemented that in a separate PR #19990 , lets pause this one until we get that merged in so we don't have to come back to this section later
maybe I should just compute the correct positive index value when we encounter a negative index, rather than doing this? Where's the best place to do that? Should that be with this or in a separate PR?
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This PR modifies `TupleGet.__init__` to automatically convert negative indexes to positive indexes instead of crashing at the assert This won't change functionality on its own, but will allow us to pass negative values in python#19972 so I think we should consider this PR a prerequisite to that one
This PR modifies `TupleGet.__init__` to automatically convert negative indexes to positive indexes instead of crashing at the assert This won't change functionality on its own, since none of the existing calling locations can pass a negative value, but will allow us to pass negative values in python#19972 so I think we should consider this PR a prerequisite to that one
This comment was marked as off-topic.
This comment was marked as off-topic.
This PR modifies `TupleGet.__init__` to automatically convert negative indexes to positive indexes instead of crashing at the assert This won't change functionality on its own, since none of the existing calling locations can pass a negative value, but will allow us to pass negative values in #19972 so I think we should consider this PR a prerequisite to that one --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Piotr Sawicki <[email protected]>
Now that #19990 is merged, this PR is ready for review. |
This PR attempts to constant fold the index value in
translate_index_expr
I'm not sure any test changes are warranted for a small PR of this nature.